package com.dnui.seven2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnui.seven2.common.R;
import com.dnui.seven2.entity.Comment;
import com.dnui.seven2.entity.Employee;
import com.dnui.seven2.service.CommentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;


    @GetMapping("/queryComments")
    public R<Page> queryComments(Integer currentPageNum, Integer everyPage ){
        //构造分页构造器
        Page pageInfo=new Page(currentPageNum,everyPage);
        //构造条件构造器
        LambdaQueryWrapper<Comment> queryWrapper=new LambdaQueryWrapper();

        //执行查询
        commentService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @PostMapping("saveComment")
    public R<String> saveComment(@RequestBody Comment comment){
        commentService.save(comment);
        return  R.success("添加成功");
    }

    @DeleteMapping("deleteComment/{commentId}")
    public R<String> deleteComment(@PathVariable Long commentId ){
        commentService.deleteComment(commentId);
        return  R.success("删除成功");
    }

    @PutMapping("updateComment")
    public R<String> updateComment(@RequestBody Comment comment){
        commentService.updateComment(comment);
        return  R.success("修改成功");
    }

}
